#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 2005;
const int MOD = 1e9 + 7;

mt19937 mt(chrono::steady_clock::now().time_since_epoch().count());
int n, m;
int a[N];
ll bit[N][N];
int lowbit(int x) { return x & -x; }
void add(int x, int y, ll d) {
  // cout << x << ' ' << y << ' ' << d << endl;
  for (int i = x; i <= n + 1; i += lowbit(i)) {
    for (int j = y; j <= n + 1; j += lowbit(j)) {
      bit[i][j] = (bit[i][j] + d) % MOD;
    }
  }
}
ll get(int x, int y) {
  ll res = 0;
  for (int i = x; i > 0; i -= lowbit(i)) {
    for (int j = y; j > 0; j -= lowbit(j)) {
      res = (res + bit[i][j]) % MOD;
    }
  }
  return res;
}
void init(int n) {
  for (int i = 1; i <= n + 1; i++)
    for (int j = 1; j <= n + 1; j++) bit[i][j] = 0;
  add(1, 1, 1);
}
void solve() {
  cin >> n;
  init(n);
  rep(i, 1, n) {
    int x;
    cin >> x;
    x++;
    // if mx > x dp[mx][mn] -> dp[mx][x]
    ll nxt = get(n + 1, x);
    per(i, n, x) {
      ll now = get(i, x);
      ll val = (nxt - now + MOD) % MOD;
      add(i + 1, x, val);
      nxt = now;
    }
    per(i, x - 1, 1) {
      ll now = get(x, i);
      ll val = (nxt - now + MOD) % MOD;
      add(x, i + 1, val);
      nxt = now;
    }
    add(x, 1, nxt);
  }
  cout << get(n + 1, n + 1) << endl;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int t;
  cin >> t;
  while (t--) solve();
  return 0;
}